package cn.edu.zzuli.wechat.user.mapper;

import cn.edu.zzuli.model.dto.JudgeDto;
import cn.edu.zzuli.model.dto.OfferOrderDto;
import cn.edu.zzuli.model.dto.RankDto;
import cn.edu.zzuli.model.entity.OfferOrder;
import cn.edu.zzuli.model.vo.order.ConditionQueryVo;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.core.toolkit.Constants;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface OfferOrderMapper extends BaseMapper<OfferOrder> {

    //获取排行榜
    @Select("select nick_name,avatar_url,count(1) as cnt from run_order join user on" +
            " ruid = uid group by ruid order by cnt desc")
    Page<RankDto> selectRankList(Page<RankDto> page);

    //按条件查询出所有用户的订单列表
    @Select("select oid as id,title,type,bounty,post_time,status from `offer_order` ${ew.customSqlSegment}")
    Page<OfferOrderDto> queryList(Page<OfferOrderDto> pageCod, @Param(Constants.WRAPPER)QueryWrapper<OfferOrderDto> wrapper);

    //通过状态插叙自己的订单列表
    @Select("select oid as id,title,type,bounty,post_time,status from `offer_order` ${ew.customSqlSegment}")
    Page<OfferOrderDto> queryListByStatus(Page<OfferOrderDto> page, @Param(Constants.WRAPPER)QueryWrapper<OfferOrderDto> wrapper);

    //得到过期时间
    @Select(" select dead_time from offer_order where oid = #{id}")
    String getDeadTime(Integer id);


    //List<OfferOrder> choose(ConditionQueryVo conditionQueryVo);

    //多条件搜索
    Page<OfferOrder> choose(@Param("conditionQueryVo") ConditionQueryVo conditionQueryVo,Page<OfferOrder> page);

    //查询出订单状态 截止时间 积分 完成时间
    @Select("SELECT run_order.ruid,finish_time,dead_time,offer_order.bounty,offer_order.status FROM " +
            "run_order JOIN USER ON uid = ruid " +
            "JOIN offer_order ON ruid = ouid  AND oid = #{id} AND roid = #{id}")
    JudgeDto findAndJudge(int id);
}
